package org.emet.entity.biz;

import java.math.BigDecimal;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.emet.jee.console.entity.BaseEntity;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

/**
 * 接运派车历史
 * 
 */

@Entity
@Table(name = "T_CARRIAGE")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Carriage extends BaseEntity {
	// 派车业务的 business NUM.
	private String bizNo;
	// --------- Information for DEAD --------//
	private String deadName;
	// 拼音码：张三----> ZS
	private String dPyName;
	private String dGender;
	private Integer dAge;
	private String deathReason;
	private java.sql.Date deadDate;
	private String hospital;

	private BigDecimal fee;
	private Boolean paied = false;

	private String contactName;
	private String cPyName;
	private String cPhone;
	private String relationShip;

	// 出车时间
	private java.util.Date date;
	// 返回时间
	private java.util.Date backDate;

	// 车辆ID
	private String vehLPN;
	// 收敛人
	private List<Employee> gathers;
	// 驾驶员
	private List<Employee> drivers;

	// 具体地点
	private String address;

	// 备注
	private String remark;

	private Integer estimateMiles = 0;

	public String getVehLPN() {
		return vehLPN;
	}

	public void setVehLPN(String vehLPN) {
		this.vehLPN = vehLPN;
	}

	public String getDeadName() {
		return deadName;
	}

	public void setDeadName(String deadName) {
		this.deadName = deadName;
	}

	public Boolean getPaied() {
		return paied;
	}

	public void setPaied(Boolean paied) {
		this.paied = paied;
	}

	public String getcPhone() {
		return cPhone;
	}

	public void setcPhone(String cPhone) {
		this.cPhone = cPhone;
	}

	public java.util.Date getBackDate() {
		return backDate;
	}

	public void setBackDate(java.util.Date backDate) {
		this.backDate = backDate;
	}

	public Integer getEstimateMiles() {
		return estimateMiles;
	}

	public void setEstimateMiles(Integer estimateMiles) {
		this.estimateMiles = estimateMiles;
	}

	public String getBizNo() {
		return bizNo;
	}

	public void setBizNo(String bizNo) {
		this.bizNo = bizNo;
	}



	public Integer getdAge() {
		return dAge;
	}

	public void setdAge(Integer dAge) {
		this.dAge = dAge;
	}

	public BigDecimal getFee() {
		return fee;
	}

	public void setFee(BigDecimal fee) {
		this.fee = fee;
	}

	public String getContactName() {
		return contactName;
	}

	public String getdPyName() {
		return dPyName;
	}

	public void setdPyName(String dPyName) {
		this.dPyName = dPyName;
	}

	public String getcPyName() {
		return cPyName;
	}

	public void setcPyName(String cPyName) {
		this.cPyName = cPyName;
	}

	public void setContactName(String contactName) {
		this.contactName = contactName;
	}



	public java.util.Date getDate() {
		return date;
	}

	public void setDate(java.util.Date date) {
		this.date = date;
	}


	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	@ManyToMany(fetch = FetchType.EAGER)
	@JoinTable(name = "T_CARRIAGE_GATHER", joinColumns = { @JoinColumn(name = "CARRIAGE_ID") }, inverseJoinColumns = { @JoinColumn(name = "GATHER_ID") })
	@Fetch(FetchMode.SUBSELECT)
	@OrderBy("id")
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	public List<Employee> getGathers() {
		return gathers;
	}

	public void setGathers(List<Employee> gathers) {
		this.gathers = gathers;
	}

	@ManyToMany(fetch = FetchType.EAGER)
	@JoinTable(name = "T_CARRIAGE_DRIVER", joinColumns = { @JoinColumn(name = "CARRIAGE_ID") }, inverseJoinColumns = { @JoinColumn(name = "DRIVER_ID") })
	@Fetch(FetchMode.SUBSELECT)
	@OrderBy("id")
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	public List<Employee> getDrivers() {
		return drivers;
	}

	public void setDrivers(List<Employee> drivers) {
		this.drivers = drivers;
	}

	public java.sql.Date getDeadDate() {
		return deadDate;
	}

	public void setDeadDate(java.sql.Date deadDate) {
		this.deadDate = deadDate;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getdGender() {
		return dGender;
	}

	public void setdGender(String dGender) {
		this.dGender = dGender;
	}

	public String getDeathReason() {
		return deathReason;
	}

	public void setDeathReason(String deathReason) {
		this.deathReason = deathReason;
	}

	public String getHospital() {
		return hospital;
	}

	public void setHospital(String hospital) {
		this.hospital = hospital;
	}

	public String getRelationShip() {
		return relationShip;
	}

	public void setRelationShip(String relationShip) {
		this.relationShip = relationShip;
	}


	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this);
	}

	@Transient
	public String toDriversString() {
		List<Employee> list = getDrivers();
		StringBuilder sb = new StringBuilder();
		for (Employee employee : list) {
			sb.append(employee.getName());
			sb.append(" ");
		}
		return sb.toString();
	}

	@Transient
	public String toGathersString() {
		StringBuilder sb = new StringBuilder();

		List<Employee> gathersList = getGathers();
		for (Employee employee : gathersList) {
			sb.append(employee.getName());
			sb.append(" ");
		}

		return sb.toString();
	}

}
